package client.gui.panels;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import controllers.ControllerIF;
import entities.Ticket;

/**
 * @author Vodi
 *
 */
public class GeneralInformationPanel extends JPanel implements PanelIF {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Structure holding all the data that the user inserted into the ticket
	 */
	private Ticket ticket;
	
	
	/**
	 * Create the panel.
	 */
	public GeneralInformationPanel(Ticket ticket) {
		this.ticket = ticket;
		
		initGUI();
	}

	/**
	 * Initialize the UI
	 */
	public void initGUI() {
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		add(Box.createVerticalStrut(20));
		
		JPanel ticketInitiatorPanel = new JPanel();
		add(ticketInitiatorPanel);
		ticketInitiatorPanel.setLayout(new BoxLayout(ticketInitiatorPanel, BoxLayout.X_AXIS));
		
		ticketInitiatorPanel.add(Box.createHorizontalStrut(20));
		
		JLabel initiatorNamePromptLabel = new JLabel("Ticket initiator name:");
		ticketInitiatorPanel.add(initiatorNamePromptLabel);
		
		ticketInitiatorPanel.add(Box.createHorizontalStrut(20));
		
		JLabel initiatorNameLabel = new JLabel(ticket.getTicketInitiator().getFirstName() + " " + ticket.getTicketInitiator().getLastName());
		ticketInitiatorPanel.add(initiatorNameLabel);
		
		ticketInitiatorPanel.add(Box.createHorizontalGlue());
		
		JLabel initiatorIdPromptLabel = new JLabel("Ticket Initiator's ID number:");
		ticketInitiatorPanel.add(initiatorIdPromptLabel);
		
		ticketInitiatorPanel.add(Box.createHorizontalStrut(20));
		
		JLabel initiatorIdLabel = new JLabel(ticket.getTicketInitiator().getId().toString());
		ticketInitiatorPanel.add(initiatorIdLabel);
		
		ticketInitiatorPanel.add(Box.createHorizontalStrut(20));
		
		add(Box.createVerticalStrut(20));
		{
			JPanel initDatePanel = new JPanel();
			add(initDatePanel);
			initDatePanel.setLayout(new BoxLayout(initDatePanel, BoxLayout.X_AXIS));
			
			initDatePanel.add(Box.createHorizontalStrut(20));
			
			JLabel initializationDatePromptLabel = new JLabel("Ticket initialization date:");
			initDatePanel.add(initializationDatePromptLabel);
			
			initDatePanel.add(Box.createHorizontalStrut(64));
			
			JLabel initDateLabel = new JLabel(ticket.getGeneralInfo().getInitDate());
			initDatePanel.add(initDateLabel);
		
			initDatePanel.add(Box.createHorizontalGlue());
		}
		add(Box.createVerticalStrut(20));
		{
			JPanel infoSystemPanel = new JPanel();
			add(infoSystemPanel);
			infoSystemPanel.setLayout(new BoxLayout(infoSystemPanel, BoxLayout.X_AXIS));
			
			infoSystemPanel.add(Box.createHorizontalStrut(20));
			
			JLabel infoSystemLabel = new JLabel("Information system: ");
			infoSystemPanel.add(infoSystemLabel);
			
			infoSystemPanel.add(Box.createHorizontalStrut(78));
			
			JTextField infoSystemTextField = new JTextField();
			infoSystemTextField.setText(ticket.getGeneralInfo().getInfoSystemName());
			infoSystemTextField.setEnabled(false);
			infoSystemTextField.setColumns(20);
			infoSystemPanel.add(infoSystemTextField);
		}
		add(Box.createVerticalStrut(20));
		{
			JPanel existingSituationPanel = new JPanel();
			add(existingSituationPanel);
			existingSituationPanel.setLayout(new BoxLayout(existingSituationPanel, BoxLayout.X_AXIS));
			
			existingSituationPanel.add(Box.createHorizontalStrut(20));
			
			JLabel existingSituationLabel = new JLabel("Existing Situation:");
			existingSituationPanel.add(existingSituationLabel);
			
			existingSituationPanel.add(Box.createHorizontalStrut(92));
			
			JScrollPane scrollPane = new JScrollPane();
			existingSituationPanel.add(scrollPane);
			
			JTextArea existingSituationTextArea = new JTextArea();
			// FIXME : if text areas are defective - set enabled as true
			existingSituationTextArea.setEditable(false);
			existingSituationTextArea.setText(ticket.getGeneralInfo().getExistingSituationDescription());
			existingSituationTextArea.setEnabled(false);
			existingSituationTextArea.setRows(6);
			existingSituationTextArea.setLineWrap(true);
			scrollPane.setViewportView(existingSituationTextArea);
		}
		add(Box.createVerticalStrut(20));
		{
			JPanel requestedChangePanel = new JPanel();
			add(requestedChangePanel);
			requestedChangePanel.setLayout(new BoxLayout(requestedChangePanel, BoxLayout.X_AXIS));
			
			requestedChangePanel.add(Box.createHorizontalStrut(20));
			
			JLabel requestedChangeLabel = new JLabel("Requested Change:");
			requestedChangePanel.add(requestedChangeLabel);
			
			requestedChangePanel.add(Box.createHorizontalStrut(82));
			
			JScrollPane requestedChangeScroll = new JScrollPane();
			requestedChangePanel.add(requestedChangeScroll);
			
			JTextArea requestedChangeTextArea = new JTextArea();
			requestedChangeTextArea.setEditable(false);
			requestedChangeTextArea.setText(ticket.getGeneralInfo().getRequestedChangedDescription());
			requestedChangeTextArea.setEnabled(false);
			requestedChangeTextArea.setRows(6);
			requestedChangeTextArea.setLineWrap(true);
			requestedChangeScroll.setViewportView(requestedChangeTextArea);
		}
		add(Box.createVerticalStrut(20));
		{
			JPanel reasonsPanel = new JPanel();
			add(reasonsPanel);
			reasonsPanel.setLayout(new BoxLayout(reasonsPanel, BoxLayout.X_AXIS));
			
			reasonsPanel.add(Box.createHorizontalStrut(20));
			
			JLabel reasonsLable = new JLabel("Reasons for the change:");
			reasonsPanel.add(reasonsLable);
			
			reasonsPanel.add(Box.createHorizontalStrut(59));
			
			JScrollPane reasonsScroll = new JScrollPane();
			reasonsPanel.add(reasonsScroll);
			
			JTextArea reasonsTextArea = new JTextArea();
			reasonsTextArea.setEditable(false);
			reasonsTextArea.setText(ticket.getGeneralInfo().getReasonForRequest());
			reasonsTextArea.setEnabled(false);
			reasonsTextArea.setRows(6);
			reasonsTextArea.setLineWrap(true);
			reasonsScroll.setViewportView(reasonsTextArea);
		}
		add(Box.createVerticalStrut(20));
		{
			JPanel commentsPanel = new JPanel();
			add(commentsPanel);
			commentsPanel.setLayout(new BoxLayout(commentsPanel, BoxLayout.X_AXIS));
			
			commentsPanel.add(Box.createHorizontalStrut(20));
			
			JLabel commentsLabel = new JLabel("Comments:");
			commentsPanel.add(commentsLabel);
			
			commentsPanel.add(Box.createHorizontalStrut(124));
			
			JScrollPane commentsScroll = new JScrollPane();
			commentsPanel.add(commentsScroll);
			
			JTextArea commentsTextArea = new JTextArea();
			commentsTextArea.setEditable(false);
			commentsTextArea.setText(ticket.getGeneralInfo().getComments());
			commentsTextArea.setEnabled(false);
			commentsTextArea.setRows(6);
			commentsTextArea.setLineWrap(true);
			commentsScroll.setViewportView(commentsTextArea);
		}
		add(Box.createVerticalStrut(20));
	}
	
	@Override
	public void setController(ControllerIF cif) {}

}
